﻿Public Class frm_restore 
    Private bus As knm2012BUS
    Dim testrt As Integer
    Dim time As Integer
    Private Sub frm_restore_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        txtfiledatabase.Enabled = False
        Timer1.Enabled = True
        Timer1.Interval = 1000
        Timer1.Stop()
    End Sub

    Private Sub btnpatch_Click(sender As System.Object, e As System.EventArgs) Handles btnpatch.Click
        Dim SelectedFile As New System.Windows.Forms.OpenFileDialog
        Dim dlgResult As DialogResult = SelectedFile.ShowDialog()
        If dlgResult = Windows.Forms.DialogResult.OK Then
            txtpatch.Text = SelectedFile.FileName
        End If
    End Sub
    Private Sub TestTextbox()
        If (Trim(txtpatch.Text) = "") Then
            MsgBox("Bạn phải lựa chọn file để khôi phục dữ liệu hệ thống", MsgBoxStyle.Exclamation, "Thông báo")
            testrt = 0
        Else
            testrt = 1
        End If
    End Sub
    Private Sub btnbackup_Click(sender As System.Object, e As System.EventArgs) Handles btnbackup.Click
        TestTextbox()
        If testrt = 1 Then
            Timer1.Start()
        End If
    End Sub
    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        time = time + 1
        ProgressBarControl1.EditValue = ProgressBarControl1.EditValue + 50
        If time = 2 Then
            Timer1.Stop()
            Restore()
        End If
    End Sub
    Private Sub Restore()
        Dim patch As String = txtpatch.Text
        Dim dbname As String = txtfiledatabase.Text
        bus = New knm2012BUS
        bus.Restore(dbname, patch)
        MsgBox("Khôi phục dữ liệu thành công", MsgBoxStyle.Information, "Thông báo")
    End Sub
    Private Sub btnclose_Click(sender As System.Object, e As System.EventArgs) Handles btnclose.Click
        Me.Close()
    End Sub
End Class